;; The first three lines of this file were inserted by DrScheme. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(planet plai/plai:1:3/lang/reader)

(define (novo-if predicado caso-then caso-else)
  (cond (predicado caso-then)
        (else caso-else)))

(define precisao 0.00000000000000000000001)

(define (perto? chute x)
  (< (abs (- (* chute chute) x)) precisao))

(define (melhorar chute x)
  (/ (+ chute (/ x chute)) 2))

(define (estimar chute x)
  (novo-if (perto? chute x) 
      chute
      (estimar (melhorar chute x) x)))

(define (raizq x) (estimar 1 x))
 
(test-inexact-epsilon precisao)
(test (raizq 36) 6.0)
(test (raizq 1) 1)
(test (/ (raizq 3) 2) (sin (/ pi 3)))
; On-Line Encyclopedia of Integer Sequences
; http://www.research.att.com/~njas/sequences/A002193
(test (raizq 2) 1.41421356237309504880168872420969807856967187537694807317667973799073247846210703885038753432764157) 
